﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_QuestionManager_AddQuestionInfo_jianda : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerCourseInfo courseInfoManager = new ManagerCourseInfo();
    //ManagerQuestionTypeInfo questionTypeManager = new ManagerQuestionTypeInfo();

    //ManagerQuestionInfo questionInfoManager = new ManagerQuestionInfo();
    ManagerQuestion objQuestion = new ManagerQuestion();
    Course objCourse = new Course();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddQuestion))
        //{
        //    Script.ShowAndHistory("您没有添加试题的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            ViewState["TypeID"] = 6;
            ViewState["UserID"] = GetCreatedByInfo().UserID;
            BinderDLL();
            InitPage();
        }
    }

    protected override void InitPage()
    {
        lab_AddQuestionInfo_danx_QuestionType.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionType", PowerCreator.LMS.Language.LanagetItemType.Page);
       

        lab_AddQuestionInfo_danx_ContentTitle.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_ContentTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionContent.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionContent", PowerCreator.LMS.Language.LanagetItemType.Page);
        
        

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnBack.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void BinderDLL()
    {
        DataTable dt_QuestionType = objQuestion.QueryQuestionType("");
        int rowindex_zuheti = 0;
        int rowindex_mingcijieshi = 0;
        for (int i = 0; i < dt_QuestionType.Rows.Count; i++)
        {
            if (dt_QuestionType.Rows[i]["QuestionTypeName"].ToString() == GetLanageValueByKey("msg_CelueSelectQuest_zuheti", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rowindex_zuheti = i;
            }
            if (dt_QuestionType.Rows[i]["QuestionTypeName"].ToString() == GetLanageValueByKey("lab_EditUserPaper_Question_Mingcijieshiti", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rowindex_mingcijieshi = i;
            }
        }
        dt_QuestionType.Rows.RemoveAt(rowindex_zuheti);
        dt_QuestionType.Rows.RemoveAt(rowindex_mingcijieshi);

        rdbtn_QuestionType.DataSource = dt_QuestionType;

        rdbtn_QuestionType.DataTextField = "QuestionTypeName";
        rdbtn_QuestionType.DataValueField = "QuestionTypeID";

        rdbtn_QuestionType.DataBind();
        for (int i = 0; i < rdbtn_QuestionType.Items.Count; i++)
        {
            if (rdbtn_QuestionType.Items[i].Text == GetLanageValueByKey("msg_CelueSelectQuest_jiandati", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rdbtn_QuestionType.Items[i].Selected = true;
            }
        }



    }
    private bool PageCheck()
    {

        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!PageCheck())
        {
            return;
        }
        VOQuestion voQuestion = new VOQuestion();
        voQuestion.QuestionIsFather = 0;
        voQuestion.FKQuestionCourseID = -1;
        voQuestion.QuestionCreateID = int.Parse(ViewState["UserID"].ToString());
        voQuestion.QuestionCreateTime = DateTime.Now;

        voQuestion.QuestionAnswer = "";            //
        voQuestion.QuestionDefaultScore = 0;
        voQuestion.QuestionDiffculty = 0;
        voQuestion.QuestionKen = "";


        int quesiontClass = 1;                 //主观题判断有问题

        voQuestion.QuestionClass = quesiontClass;    
        voQuestion.QuestionContent = txtQuestionContent.Text;
        voQuestion.QuestionParse = "";
        voQuestion.FKQuestionTypeID = int.Parse(ViewState["TypeID"].ToString());
        voQuestion.QuestionState =2;         //禁用1,启用2

        try
        {
            objQuestion.CreateQuestionOptionList(voQuestion, null);
            Script.ShowAndRedirect(this, GetLanageValueByKey("msg_CelueSelectQuest_shuruti23", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
        catch
        {
            Script.ShowAndRedirect(this, GetLanageValueByKey("msg_CelueSelectQuest_shuruti24", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
        
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("ManagerQuestionInfo.aspx");
    }

    protected void rdbtn_QuestionType_SelectedIndexChanged(object sender, EventArgs e)
    {
        string url = string.Empty;
        switch (rdbtn_QuestionType.SelectedValue)
        {
            case "1":
                url = "AddQuestionInfo_panduan.aspx";
                break;
            case "2":
                url = "AddQuestionInfo_danx.aspx";
                break;
            case "3":
                url = "AddQuestionInfo_duox.aspx";
                break;
            case "4":
                url = "AddQuestionInfo_tiank.aspx";
                break;
            case "5":
                url = "AddQuestioninfo_mingci.aspx";
                break;
            case "6":
                url = "AddQuestionInfo_jianda.aspx";
                break;
            case "7":
                url = "AddQuestionInfo_zuhe.aspx";
                break;
        }
        Script.RedirectURL(url);
    }
}
